/*
 *  $Id: Offence.cs 1233 2010-12-18 17:54:48Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008-2010 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

using AgateLib.Geometry;

using Nereal.Serialization;

namespace Ragima {
    /// <summary>
    /// Тип цели: место для перемещения и для атаки существа.
    /// </summary>
    public class OffenceTarget : MoveTarget {
        public OffenceTarget(Creature creature) : base(creature) {
        }

        public override int GetCount(AbstractObject caster) {
            int count = base.GetCount(caster);
            if (_creature.CanChangeAttack)
                count++;
            return count;
        }

        public override IEnumerable<Region> GetRegions() {
            var regions = new List<Region>(base.GetRegions());
            if (_creature.CanChangeAttack) {
                var rect = Constants.GetRowRect(_creature.Number, _creature.State == CreatureState.Offence ? 2 : 1);
                regions.Add(new CreatureAttackRegion(rect));
            }
            return regions;
        }

        public override TargetArgs GetArgs(Region region) {
            return region is CreatureAttackRegion ? new AttackTargetArgs(Request.Player, Request.Caster) : base.GetArgs(region);
        }
    }

    /// <summary>
    /// Регион, определяющий место установки и отмены атаки существа.
    /// </summary>
    public class CreatureAttackRegion : Region {
        public CreatureAttackRegion(Rectangle rect) : base(rect) {
        }

        public override void Draw() {
            Data.CardSelect1.Draw(Rect.Location);
        }

        public override void OnClick() {
            Game.Current.Target.ClickRegion(this);
        }
    }

    [TypeId("attack")]
    public class AttackTargetArgs : CreatureActionTargetArgs {
        public AttackTargetArgs() {
        }
        public AttackTargetArgs(Player player, AbstractObject caster) : base(player, caster) {
        }

        protected override void DoAction(Creature cr) {
            if (cr.State == CreatureState.Offence)
                cr.Owner.UnsetAttack(cr, true);
            else
                cr.Owner.SetAttack(cr, true);
        }
    }
}
